package com.witmed.dao.impl;

/**
 *  * 医院表
 * chenxiangyang 
 */
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.sql.rowset.CachedRowSet;

import com.witmed.dao.HospitalDao;
import com.witmed.entity.Hospital;
import com.witmed.util.DBUtils;

public class HospitalDaoImpl implements HospitalDao {

	private DBUtils db = new DBUtils();

	/**
	 * 插入医院信息
	 */
	@Override
	public int insert(Hospital hospital) {
		// TODO Auto-generated method stub

		return db.update("insert into hospital(hospital_id,hospital_name,hospital_content) values(?,?,?)",
				hospital.getHospitalId(), hospital.getHospitalName(), hospital.getHospitalContent());
	}

	/**
	 * 查询新增的医院id
	 */

	@Override
	public List<Hospital> findHospitalId(String hospitalName) {

		// TODO Auto-generated method stub
		List<Hospital> list = new ArrayList<Hospital>();
		ResultSet rs = db.query("select hospital_id from hospital where hospital_name = ?", hospitalName);
		try {
			while (rs.next()) {
				Integer hospitalId = rs.getInt("hospital_id");
				// 构建实体模型
				Hospital hospital = new Hospital(hospitalId, null);
				// 添加到集合中
				list.add(hospital);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	/**
	 * 根据id删除医院
	 */

	@Override
	public int deleteByHospitalId(int hospitalId) {
		// TODO Auto-generated method stub
		return db.update("delete from hospital where doctor_id=?", hospitalId);
	}

}
